import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class SqlGenerator2 {
	public static void main(String[] args) {
		
		
//		String[] values = {};
//		System.out.println("delete from `customerextra` where customerid="+values[0]+" and attribute='SalesRegion';");
//		System.out.println("INSERT INTO `customerextra` (`customerid`, `attribute`, `value`, `description`) VALUES ("+values[0]+", 'SalesRegion', '"+values[1]+"', '"+values[2]+"');");
		
		Map db =readFileByMap("D:\\db.txt");
		Map error = new HashMap();
		List excel = readFileByLines("D:\\excel.txt");
		BigDecimal c = new BigDecimal("0");
		for (Iterator iterator =excel.iterator(); iterator.hasNext();) {
			String[] values = (String[]) iterator.next();
			
			try{
				String key = values[0]+"-"+values[1]+"-"+values[2]+"-"+values[3];
				if(db.containsKey(key)){
					BigDecimal dbvalue = new BigDecimal(db.get(key).toString());
					BigDecimal excelvalue = BigDecimal.ZERO;
					excelvalue= new BigDecimal(values[4]);
					BigDecimal gap= dbvalue.subtract(excelvalue).abs();
					if(gap.compareTo(BigDecimal.ONE)==1)
						System.out.println(key+" "+gap);
					db.remove(key);
				}else if(!values[4].trim().equals("0")){
					error.put(key, values[4]);
				}
//				if("EUR".equals(values[1])){
//					BigDecimal tmp = new BigDecimal(Float.parseFloat(values[2]));
//					tmp = tmp.multiply(new BigDecimal("1.3"));
//					c =c.add(tmp);
//					
//				}else{
//					BigDecimal tmp = new BigDecimal(Float.parseFloat(values[2]));
//					c =c.add(tmp);
//				}
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		System.out.println(c);

	}
	
	
    public static List readFileByLines(String fileName) {
        File file = new File(fileName);
        List result = new ArrayList();
        BufferedReader reader = null;
        try {
            System.out.println("以行为单位读取文件内容，一次读一整行：");
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            int line = 1;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                // 显示行号
//                System.out.println("line " + line + ": " + tempString);
                String[] values = tempString.split("\t");
                result.add(values);
                line++;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
        return result;
    }
    public static Map readFileByMap(String fileName) {
    	File file = new File(fileName);
    	Map result = new HashMap();
    	BufferedReader reader = null;
    	try {
    		reader = new BufferedReader(new FileReader(file));
    		String tempString = null;
    		while ((tempString = reader.readLine()) != null) {
                String[] values = tempString.split("\t");
                String key = values[0]+"-"+values[1]+"-"+values[2]+"-"+values[3];
                if(result.get(key)!=null){
                	System.out.println("error= "+key);
                }
    			result.put(key,values[4]);
    		}
    		reader.close();
    	} catch (IOException e) {
    		e.printStackTrace();
    	} finally {
    		if (reader != null) {
    			try {
    				reader.close();
    			} catch (IOException e1) {
    			}
    		}
    	}
    	return result;
    }
}